package com.ricky04.aysnc;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalTime;

/**
 * Created by bgt on 2018/5/6.
 */
@SpringBootApplication
@EnableAsync
@RestController
public class SpringBootAsyncMain {
    @Autowired
    private MyAsync async;

    /**
     * 步骤1
     步骤2
     模拟耗时
     模拟耗时
     模拟耗时
     步骤3
     步骤4

     * @return
     */
    @GetMapping("/async")
    public String getAsync(){
        System.out.println("步骤1");
        async.doSomeThing();
        System.out.println("步骤4");
        return "success"+ LocalTime.now();
    }

    /**
     async2步骤1
     2018/05/06-10:20:03 [qtp237503491-27] INFO  org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor- No task executor bean found for async processing: no bean of type TaskExecutor and no bean named 'taskExecutor' either
     async2步骤4
     async2步骤2
     模拟耗时
     模拟耗时
     模拟耗时
     async2步骤3

     * @return
     */
    @GetMapping("/async2")
    public String getAsync2(){
        System.out.println("async2步骤1");
        async.doSomeThing2();
        System.out.println("async2步骤4");
        return "success2"+ LocalTime.now();
    }


    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootAsyncMain.class, args);


    }
}
